<template>
    <div class="" id="task-my-task-check-modal-container">
        <h2 class="task-my-task-check-model-title">{{checkTask.subject}}</h2>
        <Divider class="task-my-task-divider">任务时间</Divider>
        {{checkTask.pubDate}} 至 {{checkTask.deadLine}}
        <Divider class="task-my-task-divider">任务描述</Divider>
        <p class="task-my-task-check-model-describe">{{checkTask.describe}}</p>
        <Divider class="task-my-task-divider">任务对象</Divider>
        <p class="task-my-task-check-model-object" v-for="(item, index) in getTaskObject()" :key="`task-object-${index}`">{{getTaskObjectName(item)}}</p>
        <Divider class="task-my-task-divider">任务附件</Divider>
        <Image_Loader class="task-issue-form-items" :iList="checkTask.imgList" :editMode="false"/>
        <Divider class="task-my-task-divider">提交内容</Divider>
        <Input class="task-issue-form-context" v-model="myContent" type="textarea" :rows="4" :autosize="{minRows: 4,maxRows: 4}" placeholder="输入提交内容" />
        <Image_Loader @on-change="getFromImgs" :iList="myImgs" class="task-issue-form-items" />
    </div>
</template>

<script>
import Image_Loader from "@iload/vue";
import local_vuex from "@task/js/vuex";

export default {
    data() {
        return {
            myContent: "",
            myImgs: [],
            taskObjects: []
        }
    },
    props: {
        checkTask: {
            type: Object
        }
    },
    components: {
        Image_Loader
    },
    watch: {
        checkTask() {
            this.taskObjects = this.getTaskObject();
            let me = this.checkTask.me;
            this.myContent = me.context == null ? "" : me.context.replace("<br>", "\n");
            this.myImgs = me.imgs == null ? [] : me.imgs || [];
            this.sendMessage();
        },
        myContent() {
            this.sendMessage();
        },
        myImgs() {
            this.sendMessage();
        }
    },
    methods: {
        getTaskObject() {
            let ct = this.checkTask;
            switch(ct.type) {
                case 0: return ct.deptList;
                case 1: return ct.deptList[0].groupList;
                case 2: return ct.deptList[0].groupList[0].studentList;
            }
        },
        getTaskObjectName(v) {
            switch(this.checkTask.type) {
                case 0: return v.deptName;
                case 1: return v.groupName;
                case 2: return v.name;
            }
        },
        sendMessage() {
            let context = this.myContent.replace("\n", "<br>");
            this.$emit("on-change", {
                complete: this.checkTask.me.flag == 1,
                imgs: this.myImgs,
                content: context
            })
        },
        getFromImgs(v) {
            this.myImgs = v;
        }
    }
}
</script>

<style lang="scss">
@import "@task/scss/my-task-modal";
</style>